package alpaca.core;

import java.beans.PropertyChangeListener;
import java.util.Date;

import alpaca.util.DBConfigData;

/**
 * Defines the model.
 *
 */
public interface IServerModel extends PropertyChangeListener{

	/**
	 * A method to be called for the initiation of information after 
	 * the gui has been created.
	 */
	void init();

	/**
	 * Adds a listener to listen to the ServerModel, this should be done
	 * by the view component(s) that wish to get updates in the model.
	 * 
	 * @param pcl
	 */
	void addPropertyChangeListener(PropertyChangeListener pcl);
	
	/**
	 * Removes a listener.
	 * 
	 * @param pcl
	 */
	void removePropertyChangeListener(PropertyChangeListener pcl);

	/**
	 * Starts the server and connects to the database. Users should be able to connect
	 * and all other methods in the ServerModel should function after this has been called.
	 * 
	 * @param port The port on which the server should listen on
	 * @param configData The information needed to connect to the database
	 */
	void start(int port, DBConfigData configData);
	/**
	 * Stops the server and closes the connection to the database subsystem.
	 */
	void stop();

	/**
	 * Creates a user and saves it in the database.
	 * 
	 * @param firstName
	 * @param lastName
	 * @param email
	 * @param password
	 */
	void createUser(String firstName, String lastName, String email,
			String password);
	
	/**
	 * Edits a user and saves it in the database. All online users that needs
	 * information about the change needs to be updated.
	 * 
	 * @param user IUser which is to be edited
	 * @param firstName The changed first name
	 * @param lastName The changed last name
	 * @param email The changed email
	 * @param password 
	 * @param active Sets the user inactive or active
	 */
	void editUser(IUser user, String firstName, String lastName,
			String email, String password, boolean active);

	/**
	 * Removes a user. All online users that needs
	 * information about the change needs to be updated.
	 * 
	 * @param user The user which is to be removed
	 */
	void removeUser(IUser user);
	
	/**
	 * Search for user logs given a few parameters. This search method is only
	 * for logs made for messages going one way.
	 * 
	 * @param fromUser The user the messages are sent from
	 * @param toUser The user the messages are sent to
	 * @param fromDate From what date and forward the messages are from
	 */
	void searchUserLogs(IUser fromUser, IUser toUser, Date fromDate);

}